<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目基本信息列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
         <div class="fieldBox col_50">
                    <div class="label">项目名称</div>
                <div class="field">
                    <input name="fncprjnm" id="fncprjnm" type="text" class="ui-textbox" value="${fncprjnm}" >
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox col_50">
                <div class="label">金融机构</div>
                <div class="field">
                    <input name="fncinsid" id="fncinsid" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
                </div>
             </div>
             <div class="fieldBox col_50">
                <div class="label">项目状态</div>
                <div class="field">
                    <input name="prjstcd" id="prjstcd" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
                <div style="display: none">
                </div>
             </div>               
         </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" onclick="searchBtn();"  class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
               <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新建项目</span>
               <span id="flowStartBtn" class="sq-button sq-button-round" onclick="flowStart();">发起流程</span>
               <span id="flowLoadBtn" class="sq-button sq-button-round" onclick="loadFlow()">流程信息</span>
            </div>

			
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div> 
</div>

<script type="text/javascript">
	var grid = null;
	var queryFlag ="${queryFlag}"; //只查询列表
	$(function () {
		initcombobox();
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbuss/fncprjbscinfo/initList.do',
	    	method : 'get',	 
	    	
	        columns: [
	            { display: '项目状态', name: 'fncprjstNM', minWidth: 140 ,enabledSort:true},  
	            { display: '融资机构', name: 'fncinsNM', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '融资报价', name: 'fncscmNM', minWidth: 140 , enabledSort:true}, 
	            
	            { display: '项目编号', name: 'fncprjid', minWidth: 140 , 
                        render: function (rowdata, rowindex, value, column) { 
	            		
	            		var h = '';
	            			if(value&&value!="null"){
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')">'+value+'</a>'
	            			}
	                        return h;
	            		},
	            	enabledSort:true}, 
	          

	            { display: '项目名称', name: 'fncprjnm', minWidth: 200 , enabledSort:true}, 
	            { display: '融资资产种类', name: 'astNm', minWidth: 200 , enabledSort:true}, 

	            { display: '项目金额', name: 'fncprjamt', minWidth: 140 ,
	            	 render: function (rowdata, rowindex, value, column) { 
		            		
		            		var h='';
		            		if(value&&value!="null"){
		            		    h+=fmoney(value/100.00, 2);
		            		}
		                        return h;
		            		},
	            	
	            	enabledSort:true}, 
	            

	            { display: '融资金额', name: 'fncfiamt', minWidth: 140 , render: function (rowdata, rowindex, value, column) { 
            		
            		var h = '';
            			if(value&&value!="null"){
            		    h+=fmoney(value/100.00, 2);
            			}else{
            			h+="0.00";
            			}
                        return h;
            		},
        	
        	enabledSort:true}, 
        

	            { display: '是否作废', name: 'isdel', minWidth: 80 , enabledSort:true, 
        		render: function (rowdata, rowindex, value, column) { 
        			if(value==1){
        				return "是"
        			}else{
        				return "否"
        			}
        		
        		}

	            }, 
	          
 
	            getOptColumn()
	        ],
	        pageSize:50,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    
	
	
	});
	
	//获取操作列
	function getOptColumn(){
		if(queryFlag!="query"){
		var column = {
                display: '操作',
                isSort: false,
                width: 190,
                align:'left',
                render: function (rowdata, rowindex, value){
                	 var h="";
                if(rowdata.fncprjstcd=="0"){
                	
                	  h='<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                      h+="'"+rowdata.id+"'";
                      h+=')"><i class="sqBtnIco_4"></i>修改</a>'
                      h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
                      h+="'"+rowdata.id+"'";
                      h+=')"><i class="sqBtnIco_7"></i>删除</a>';
                }else if(rowdata.fncprjstcd==7){// && (rowdata.astId==1 || rowdata.isABS==1) //优化-项目状态为正常的均可“修改资产”
                	  h='<a class="sq-button-hasicon" href="javascript:asspackBtn(';
                      h+="'"+rowdata.id+"'";
                      h+=')"><i class="sqBtnIco_4"></i>修改资产</a>'
                      h+='<a class="sq-button-hasicon" href="javascript:detailBtn(';
                      h+="'"+rowdata.id+"'";
                      h+=')"><i class="sqBtnIco_4"></i>详情</a>';
                }else{
                	  h='<a class="sq-button-hasicon" href="javascript:detailBtn(';
                      h+="'"+rowdata.id+"'";
                      h+=')"><i class="sqBtnIco_4"></i>详情</a>';
                }
                   
           		
                	/*   h+='<a class="sq-button-hasicon" href="javascript:commShowFlow(';
                      h+="'"+rowdata.pInstId+"'";
                      h+=')"><i class="sqBtnIco_7"></i>查看流程</a>' */
                    return h;
                }
            }
		return column;
		}else{
			var column =  {};
			return column;
		}
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();

		var timestamp=new Date().getTime();
		Add_navTab('fnc_prj_bsc_info_add'+timestamp,'添加项目基本信息信息','<%=path%>/rfbuss/fncprjbscinfo/toAddPage.do?currentTabid='+currentTabid,callback);
	}
	
	function searchBtn(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
        //	alert(name+":"+data[name]);
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	function modifyBtn(id){
		var callback = function(){
			 grid.reload();
		}
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		} */
		var fromPrjFlag = true;
		var _flag = $("#fromPrjFlagId").val();//来自哪里
		if(StringUtils.isNotEmpty(_flag)){
			if(_flag == 'false'){
				fromPrjFlag = false;
			}
		}
		 var TAB=top.mainApp.parentTab;
         var currentTabid=TAB.getSelectedTabItemID();
		//查询参数
		var detailFlag = false;
	//	var params = "?fromPrjFlag="+fromPrjFlag+"&id="+id+"&detailFlag="+detailFlag;
	var params="?id="+id+"&currentTabid="+currentTabid;
		//如果客户ID存在则加入参数

		//var id = selectedRows[0].id;
		Add_navTab('fnc_prj_bsc_info_add'+id,'修改项目基本信息信息','<%=path%>/rfbuss/fncprjbscinfo/toAddPage.do'+params,callback);
	}
	//删除所选模板信息
	function removeBtn(id){
		var _ids = [];
			_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
		
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/rfbuss/fncprjbscinfo/remove.do?id='+id,
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	function detailBtn(id){

		
		Add_navTab('tab_project_detail'+id,'项目基本信息详情','<%=path%>/rfbuss/fncprjbscinfo/toDetailPage1.do?id='+id);
	}
	function asspackBtn(id){

		
		Add_navTab('tab_project_mass'+id,'修改资产包','<%=path%>/rfbuss/fncprjbscinfo/viewAssPackInfoDetail.do?prjid='+id+'&&flag=1');
	}	
	
	
	//启动流程
	function flowStart(){
		
		var selectedRows = grid.getSelectedRows();
		var _astNm = selectedRows[0].astNm;
		var _fncfiamt = selectedRows[0].fncfiamt;
		
		//if(_astNm!="信用" &&(isNaN(_fncfiamt) || _fncfiamt-0==0) ){
			
		//	$.ligerDialog.SQalert({content: "融资金额不能为0，请修改或更换资产包", SQ_type: "warning"});	
		//return;
		//}
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var modelTyp = "R004";
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	//alert(json.procDefKey);
            	//alert(json.procDefId);
            	//alert(json.procNo);
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		var _id = selectedRows[0].id;
        	
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			id:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/rfbuss/fncprjbscinfo/addFlowStart.do',
            		success:function(msg){
            			wait_dialog.close();
            			 if(msg.success == 1){
           					 UIUtils.alertSuccessHold1(msg.info);
            				 grid.reload();
            			 }else{
           					 UIUtils.alertErrorHold1(msg.info);
            			 }
            		}
            	});
            }
        });
	}
	
	
	
	
	
 
  function clearBtn(){
    $("#searchBar").ligerForm();
			var form = new liger.get("searchBar");
			//form.clear(); 
			form.setData({
				fncinsid:"",
				fncprjnm:"",
				prjstcd:"",

			 });
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    }
	}
	
	function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
	
	var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		  var combobox=  $("#fncinsid").ligerComboBox({
	    	     data:frilist,
	             selectBoxWidth: 270,
	             selectBoxHeight: 150,
	             valueField: "id",
	             textField: "fundRasInsNm",
	             autocomplete: function (e){
	                 filter_autoComboboxData(e.key, this);
	                 e.show();
	             }
	          //   onSelected: function ()
	         //    {
	          //   var obj=combobox.getSelected();
	        //       var newData1 = new Array();
	    
	           //         for (i = 0; i < firtypelist.length; i++)
	           //         {
	                     
	           //             if (firtypelist[i].key == obj.insTypeCd)
	           //             {
	                        
	           //                 newData1.push(firtypelist[i]);
	          //              }
	          //          }
	          //    }
	             });
		  
		  $("#prjstcd").ligerComboBox({
    		   url:'<%=path%>/rfbuss/fncprjbscinfo/getStcdList.do',
			        ajaxType :'GET', 
    	          selectBoxWidth: 270,
    	          selectBoxHeight: 150,
    		      valueField: "key", 
    		      textField: "value",
    		    
    		     }); 
	 }
	 
	//流程信息
		function loadFlow(){
			var selectedRows = grid.getSelectedRows();
	        if (selectedRows.length != 1) {
	            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
	            return;
	        }
			$.ligerDialog.SQopen({
	            cls: 'noBorder_Dialog',
	            width: 800,
	            height:500,
	            title : '再融资项目流程信息',
	            url:'<%=path%>/rfbuss/fncprjbscinfo/toprjFlow.do?id='+selectedRows[0].id,
	        });
		}
</script>

</body>
</html>